package com.apes.fn.scm.rebatePolicy.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.account.account.model.Cooperation;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.finance.model.IncomeType;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Brand;
import com.apes.scm.masterdata.product.model.Classify;
import com.apes.scm.masterdata.product.model.Product;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 功能：返利政策执行表
 *
 * @author cyy
 * @time 14:00
 * @date 2023/9/20
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = RebatePolicyExecute.CONST_TABLE_NAME)
public class RebatePolicyExecute extends Model {

    public static final String CONST_TABLE_NAME = "fn_rebate_policy_execute";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "返利政策执行表编码", padding = 8)
    private String id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "rebate_policy_id", referencedColumnName = "id")
    @Comment("返利政策号")
    private RebatePolicy rebatePolicy;

    @Column(name = "rebate_policy_item_id", length = 250)
    @Comment("返利政策明细号")
    private String rebatePolicyItemId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "supplier_id", referencedColumnName = "id")
    @Comment("供应商")
    private PartyRole supplier;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "period_type", referencedColumnName = "id")
    @Comment("返利类型")
    private Enumeration periodType;//001278 月返;001276 季返;001280 年返

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "start_date")
    @Comment("有效期起")
    private Date startDate;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "end_date")
    @Comment("有效期止")
    private Date endDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "platform_company_id", referencedColumnName = "id")
    @Comment("平台公司")
    private PartyRole platformCompany;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "income_type_id", referencedColumnName = "id")
    @Comment("费用类型")
    private IncomeType incomeType;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cooperation_id", referencedColumnName = "id")
    @Comment("合作方式")
    private Cooperation cooperation;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tax_id", referencedColumnName = "id")
    @Comment("返利税率")
    private Tax tax;

    @Column(name = "rebate", nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    @Comment("返利率/额")
    private double rebate = 0;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "rebate_benchmark", referencedColumnName = "id")
    @Comment("计算基数")
    private Enumeration rebateBenchmark;//002466 数量;002465 金额

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "classify_id", referencedColumnName = "id")
    @Comment("品类")
    private Classify classify;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "brand_id", referencedColumnName = "id")
    @Comment("品牌")
    private Brand brand;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @Column(name = "priority", length = 16)
    @Comment("优先级(1供应商 2品类 3品类+品牌 4商品)")
    private Integer priority;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "rebate_dimension", referencedColumnName = "id")
    @Comment("返利维度")
    private Enumeration rebateDimension;//002468 供应商;002467 品类;002469 品类+品牌;002470 商品
}
